using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InduMall.Core.Models.Mapping
{
    public class ProductStockMap : EntityTypeConfiguration<ProductStock>
    {
        public ProductStockMap()
        {
            // Primary Key
            this.HasKey(t => t.ProductId);

            // Properties
            this.Property(t => t.ProductId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Sku)
                .IsRequired()
                .HasMaxLength(60);

            // Table & Column Mappings
            this.ToTable("ProductStock");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.Sku).HasColumnName("Sku");
            this.Property(t => t.StockStatus).HasColumnName("StockStatus");

            // Relationships
            this.HasRequired(t => t.Product)
                .WithOptional(t => t.ProductStock);
            this.HasRequired(t => t.StockStatu)
                .WithMany(t => t.ProductStocks)
                .HasForeignKey(d => d.StockStatus);

        }
    }
}
